home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* SOURCE CODE FILE */
- /********************************************************************/
- /*
- * >>> File name: 5.1 DrawWindow.c
- *
- * >>> Purpose: Methods for Rectangle Object
- * >>> Project: PoopDraw Version 1
- * >>> Date: 2/20/89
- * >>> By: Adam Treister
- *
- */
- /********************************************************************/
- /* For Your Information 1802 Hillside Rd. SB CA 93101 */
- /********************************************************************/
-
- #include "PoopDrawInc"
-
- void DrawOutline(Rect r,int curTool);
-
- typedef struct
- {
- _StdObjectFields
- ObjectHandle drawPanel;
- ControlHandle vScrollBar,hScrollBar;
- Point curOrigin;
- ObjectHandle doc; /* info about files and printing */
-
- } WindowDataRec,*WindowDataPtr,**WindowDataHandle;
-
-
- /***** Public Functions *********************************************/
- /*
- WindowPtr NewDrawWindow(void);
- */
- /***** Private Functions ********************************************/
-
- DrawWinDispatch(WindowDataHandle ObjectH,int message,LPtr ParmP);
- WindowPtr NewDrawWindow(void);
- private void Dispose(WindowPtr wP);
- private void MouseDown(WindowPtr wP);
- private void Grow(WindowPtr wP);
- private void KeyDown(WindowPtr wP);
- private void Update(WindowPtr wP);
- private void Activate(WindowPtr wP);
- private void DeActivate(WindowPtr wP);
- private WindowDataHandle GetWinData(WindowPtr wP);
-
- /***** Local Defines & Includes *************************************/
-
- #define UntitledWindowName "\pUntitled"
-
- /********************************************************************/
-
- DrawWinDispatch(ObjectH,message,ParmP)
- WindowDataHandle ObjectH;
- int message;
- LPtr ParmP;
- {
- WindowPtr wP;
- wP = (*ObjectH)->port;
- switch (message)
- {
- case CLOSE:
- case DISPOSE: Dispose(wP); break;
- case MOUSEDOWN: MouseDown(wP); break;
- case UPDATE: Update(wP); break;
- case ACTIVATE: Activate(wP); break;
- case DEACTIVATE: DeActivate(wP); break;
- case GROW: Grow(wP); break;
- default: Dispatch((*ObjectH)->drawPanel,message,ParmP);
-
- } }
-
- /* ------------------------------------------------------------ */
- /* */
- /* New Draw Window */
- /* */
- /* ------------------------------------------------------------ */
-
- WindowPtr NewDrawWindow()
- {
- WindowPtr wP;
- Rect BoundsRect;
- WindowDataHandle WinData;
- extern Boolean DEBUG;
-
- BoundsRect = screenBits.bounds;
- BoundsRect.top += 40;
-
- WinData = _GetHandleToRecord(WindowDataRec);
- NullOutHandle(WinData);
- wP = NewWindow (NULL, &BoundsRect, UntitledWindowName,
- true, documentProc, -1L,true, (long) WinData);
-
- SetPort(wP);
- (*WinData)->port = wP;
- (*WinData)->dispatch = DrawWinDispatch;
-
- New(DRAWPANEL,WinData,&(*WinData)->drawPanel);
- return (wP);
- }
-
- /* ------------------------------------------------------------ */
- /* */
- /* Dispose Document Window */
- /* */
- /* */
- /* ------------------------------------------------------------ */
-
- void Dispose(wP)
- WindowPtr wP;
-
- {
- WindowDataHandle TheWindowData = GetWinData(wP);
-
- Dispatch((*TheWindowData)->drawPanel,DISPOSE,NULL);
- DisposeHandle(TheWindowData);
- DisposeWindow(wP);
- }
-
-
- /* ------------------------------------------------------------ */
-
- void MouseDown(wP)
- WindowPtr wP;
- {
- short PartCode;
- ControlHandle ctrlH;
- extern EventRecord Event;
- register Point pt;
-
- pt = Event.where;
- GlobalToLocal(&pt);
- PartCode = FindControl(pt, wP, &ctrlH);
- /* if (PartCode)
- HandleScrollBars (wP,ctrlH,pt, PartCode);
- else
- */ {
- WindowDataHandle WinData = GetWinData(wP);
- Dispatch((*WinData)->drawPanel,MOUSEDOWN,NULL);
- }
- }
- /*------------------------------------------------------------------*/
-
- void Grow(wP)
- WindowPtr wP;
- {
- WindowDataHandle WinData;
- long newSize;
- Rect oldRect,growZone;
- extern EventRecord Event;
- int newH,newV;
-
- WinData = GetWinData(wP);
- growZone = screenBits.bounds;
- growZone.left = 100; growZone.top = 260;
- newSize = GrowWindow(wP,Event.where,&growZone);
- if (!newSize ) return;
-
- newH = LoWord(newSize); newV = HiWord(newSize);
- SizeWindow(wP,newH,newV,TRUE);
- Dispatch((*WinData)->drawPanel,RESIZE,NULL);
- ClipRect(&wP->portRect);
- EraseRect(&wP->portRect);
- InvalRect(&(wP->portRect));
- }
-
- /* ------------------------------------------------------------ */
- /* */
- /* Update */
- /* */
- /* */
- /* ------------------------------------------------------------ */
-
- void Update(wP)
- WindowPtr wP;
-
- {
- WindowDataHandle WinData = GetWinData(wP);
- Rect r;
-
- r = wP->portRect;
- ClipRect(&r);
- DrawControls(wP); /* there are none, unless you add scrolling */
- DrawGrowIcon(wP);
- r.right -= ScrollBarWidth; r.bottom -= ScrollBarWidth;
- ClipRect(&r);
- Dispatch((*WinData)->drawPanel,UPDATE,NULL);
- }
- /*--------------------------------------------------------------
- * Activate
- *----------------------------------------------------------------*/
-
- void Activate(wP)
- WindowPtr wP;
- {
- /* activation of controls goes here */
- }
-
- /*--------------------------------------------------------------
- * Deactivate
- *----------------------------------------------------------------*/
- void DeActivate(wP)
- WindowPtr wP;
- {
- /* deactivation of controls goes here */
- }
-
-
- /* ------------------------------------------------------------ */
- /* */
- /* GetWindowDataHandle */
- /* */
- /* This get the WindowDataHandle from the refCon field of */
- /* the window passed to the function. */
- /* */
- /* ------------------------------------------------------------ */
-
-
- WindowDataHandle GetWinData(wP)
- WindowPtr wP;
- {
- return((WindowDataHandle) GetWRefCon(wP));
- }
-
-